# -*- coding: utf-8 -*-
"""
@Time ： 2024/9/26 10:19
@Auth ： 周瑞东 Ryan.Zhou
@File ：signals_controller.py
"""

from typing import Dict, Union
from pages.page_home import PageHome

from controllers.controller_core import ControllerCore

# 使用 Union 来定义 XI与Y的联合类型
PageType = Union[PageHome]
SubPageType = Union[PageHome]
ControllerType = Union[ControllerCore]


class SignalsController:
    def __init__(self,
                 pages:  Dict[str, PageType],
                 subpages_settings:  Dict[str, SubPageType],
                 controllers: Dict[str, ControllerType]):
        self.pages = pages
        self.sub_pages_settings = subpages_settings
        self.controllers = controllers

    def connect_signals(self):
        self.controllers["ctrl_core"].t_monitor_conn.sigs.update_navi_time.connect(self.controllers["ctrl_core"].on_sig_update_time)
        self.controllers["ctrl_core"].t_monitor_conn.sigs.data_air_quality.connect(self.pages["page_home"].on_sig_update_air_data)
        self.controllers["ctrl_core"].t_monitor_conn.sigs.data_envir.connect(self.pages["page_home"].on_sig_update_envir_data)

        # self.pages["page_diagnosis"].signals.start_daq.connect(self.sub_pages_settings["page_settings_e1682"].on_pb_start_e1682)
        # self.pages["page_diagnosis"].signals.stop_daq.connect(self.sub_pages_settings["page_settings_e1682"].on_pb_stop_e1682)

        # self.pages["page_diagnosis"].signals.start_power.connect(self.sub_pages_settings["page_settings_power"].on_pb_start_power)
        # self.pages["page_diagnosis"].signals.stop_power.connect(self.sub_pages_settings["page_settings_power"].on_pb_stop_power)

        # # self.sub_pages["page_settings_e1682"].signals.timer_update_curve.connect(self.pages["page_diagnosis"].on_sig_update_curve_old)
        # # self.sub_pages["page_settings_e1682"].signals.timer_update_curve.connect(self.sub_pages["page_test"].on_sig_update_curve)
        # self.sub_pages_settings["page_settings_e1682"].signals.thread_update_curve.connect(self.pages["page_diagnosis"].on_sig_update_curve)
        # self.sub_pages_settings["page_settings_e1682"].signals.thread_update_curve.connect(self.sub_pages_settings["page_test"].on_sig_update_curve)
        # self.sub_pages_settings["page_settings_e1682"].signals.daq_running_para.connect(self.pages["page_diagnosis"].on_sig_update_daq_status)

        # self.sub_pages_settings["page_settings_power"].signals.power_running_status.connect(self.pages["page_diagnosis"].on_sig_update_power_status)

        # self.controllers["ctrl_core"].t_monitor_conn.sigs.ping_result_e1682.connect(self.sub_pages_settings["page_settings_e1682"].on_sig_ping_result)
        # self.controllers["ctrl_core"].t_monitor_conn.sigs.serial_find_result.connect(self.sub_pages_settings["page_settings_power"].on_sig_connect_result)
        # self.controllers["ctrl_core"].t_monitor_conn.sigs.update_navi_time.connect(self.controllers["ctrl_core"].on_sig_update_time)
        # self.controllers["ctrl_core"].t_monitor_conn.sigs.power_states.connect(self.sub_pages_settings["page_settings_power"].on_sig_update_power_states)

        # self.controllers["ctrl_core"].t_monitor_conn.sigs.coil_temp.connect(self.sub_pages_settings["page_settings_power"].on_sig_coil_temp)
        # self.controllers["ctrl_core"].t_monitor_conn.sigs.coil_temp.connect(self.pages["page_diagnosis"].on_sig_coil_temp)


        # self.t_monitor_conn.sigs.ping_result_e1682.connect(self.page_settings_e1682.on_sig_ping_result)
        # self.t_monitor_conn.sigs.serial_find_result.connect(self.page_settings_power.on_sig_connect_result)
        # self.t_monitor_conn.sigs.update_navi_time.connect(self.__update_time)
        # self.t_monitor_conn.sigs.power_states.connect(self.page_settings_power.on_sig_update_power_states)
        # # 发送温度
        # self.t_monitor_conn.sigs.coil_temp.connect(self.page_settings_power.on_sig_coil_temp)
        # self.t_monitor_conn.sigs.coil_temp.connect(self.page_diagnosis.on_sig_coil_temp)
        # 在这里连接所有的信号
        # self.submodules["module1"].some_signal.connect(self.submodules["module2"].some_slot)
        # ... 其他信号连接逻辑
